package com.autocloud.model;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.MappedSuperclass;
import java.text.DecimalFormat;
import java.text.Format;
import java.time.LocalDateTime;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author zhongwb
 * @version 1.0
 * @date 2019/12/2 11:23 下午
 */
@MappedSuperclass
@Accessors(chain = true)
@Data
public abstract class Base {

    /**
     * id
     */
    @Id
    @Column(length = 32)
    private String id = UUID.randomUUID().toString().replace("-", "");
    /**
     * 标题
     */
    @Column
    private String title;
    /**
     * 是否禁用(业务上的禁用)
     */
    @Column
    private String disabled;
    /**
     * 创建时间
     */
    @Column(length = 30)
    private String createtime = LocalDateTime.now().toString();
    /**
     * 创建人
     */
    @Column(length = 32)
    private String creator;
    /**
     * 更新时间
     */
    @Column(length = 30)
    private String updatetime = LocalDateTime.now().toString();
    public static AtomicInteger count = new AtomicInteger(0);

    @Lob
    @Column(columnDefinition = "TEXT")
    protected String description;
    private static Format ranksFormat = new DecimalFormat("0000");
    /**
     * 排序
     */
    @Column(length = 30)
    private String ranks;

    public static String getRankIncrement() {
        count.incrementAndGet();
        return "c" + ranksFormat.format(count.get());
    }
}
